package cn.dc406.labc406mgr.controller;

import cn.dc406.labc406mgr.entity.Items;
import cn.dc406.labc406mgr.mapper.ItemsWapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class ItemsController {
    @Autowired(required = false)//注入相应对的内容
    ItemsWapper itemsWapper;


    @CrossOrigin("http://localhost:8080")
    @ResponseBody
    @RequestMapping("/selectbyID")
    public List<Items> selectbyID(int id)
    {
        System.out.println("selectone");
        List<Items> items=itemsWapper.selectbyID(id);
        System.out.println(items);
        return items;
    }

    @CrossOrigin("http://localhost:8080")
    @ResponseBody
    @RequestMapping("/selectbyName")
    public List<Items> selectbyName(String name)
    {
        System.out.println("selectName");
        List<Items> items=itemsWapper.selectbyName(name);
        System.out.println(items);
        return items;
    }

    @CrossOrigin("http://localhost:8080")
    @ResponseBody
    @PostMapping("/UpdateItem")
    public Boolean UpdateItem(@RequestBody Items items)
    {
        System.out.println("helow");
        return itemsWapper.UpdateItem(items);
    }

    @CrossOrigin("http://localhost:8080")
    @ResponseBody
    @PostMapping("/InsertItem")
    public Boolean InsertItem(@RequestBody Items items)
    {
        System.out.println("InsertItem");
        return itemsWapper.InsertItem(items);
    }

    @CrossOrigin("http://localhost:8080")
    @ResponseBody
    @RequestMapping("/deleteItem")
    public Boolean deleteItem(int id)
    {
        System.out.println("delete");
        return itemsWapper.deleteItem(id);
    }

}
